package com.cmbyc.todolist.mp;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;

public class CodeGenerator {
    public static void main(String[] args) {

//        List<String> tables = new ArrayList<>();
//        tables.add("config_info");

        String ip = "jdbc:mysql://localhost:3306/";
        String dataBase = "cmbyc";
        String author = "CYF";
        String moduleName = "todolist";
        String modulePackage = "todolist";
        String entityPackage = "todolist";


        FastAutoGenerator.create(ip+dataBase, "root", "123456")
                .globalConfig((scanner, builder) -> {
                    builder.author(author) // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .outputDir(System.getProperty("user.dir") + "\\" + "\\src\\main\\java"); // 指定输出目录
                })
                .packageConfig((scanner, builder) -> {
                    builder.parent("com.cmbyc") // 设置父包名
                            .controller(modulePackage.concat(".controller"))
                            .service(modulePackage.concat(".service"))
                            .serviceImpl(modulePackage.concat(".service.impl"))
                            .mapper(modulePackage.concat(".mapper"))
                            .xml(modulePackage.concat(".mapper.xml"))
                            //.moduleName()
                            .entity(entityPackage.concat(".entity"))
                    .pathInfo(Collections.singletonMap(OutputFile.entity,System.getProperty("user.dir") + "\\src\\main\\java\\com\\cmbyc\\todolist\\entity")); // 设置父包模块名
//                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, System.getProperty("user.dir") + "\\src\\main\\resources\\mapper")); // 设置mapperXml生成路径
                })
                .strategyConfig((scanner, builder) -> {
                    builder.addInclude((scanner.apply("请输入表名？")))
                            // 设置需要生成的表名
                            .addTablePrefix("t_", "c_")
                            //service
                            .serviceBuilder()
                            .formatServiceFileName("%sService")
                            .entityBuilder()
                    ; // 设置过滤表前缀
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }
}

